package events.listenerWrappers;

import java.util.EventListener;
import java.util.EventObject;

import zerdlib.events.GenericListener;
import zerdlib.events.ListenerWrapper;


public abstract class GenericListenerWrapper<Listener extends EventListener> implements GenericListener, ListenerWrapper<Listener> {
	protected final Listener wrapped;
	
	public GenericListenerWrapper(Listener listener) {
		super();
		this.wrapped = listener;
	}

	@Override
	public abstract void onEvent(EventObject ev);

	@Override
	public boolean equals(Object obj) {
		if(obj == null)
			return false;
		if(obj instanceof GenericListenerWrapper)
			return wrapped==((GenericListenerWrapper<?>)obj).wrapped;
		if(obj instanceof EventListener)
			return wrapped==obj;
		return false;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Listener getWrappedListener() {
		if(wrapped instanceof ListenerWrapper<?>) {
			return ((ListenerWrapper<Listener>) wrapped).getWrappedListener();
		} else {
			return wrapped;
		}
	}

}
